iT邦幫忙

2025 iThome 鐵人賽

DAY 9
0
自我挑戰組

cpe30天練習系列 第 9

cpe練習day9

  • 分享至 

  • xImage
  •  

今天是練習cpe的TeX Quotes題目
##程式碼

#include <iostream>
using namespace std;

string str;
int count;
int main() 
{	
	while(getline(cin , str))
	{
		for(int i = 0 ; i<str.length() ; i++)
		{
			if(str[i] == '"')
			{
				if(count%2 == 0)
				{
					cout <<  "``";
				}
				else
				{
					cout <<"''";
				}
				count++;
			}
			else
			{
				cout << str[i];
			}
		}
		cout << endl; 
	}
   
    return 0;
}

##解題方向

  • getline(cin, str):讀取一整行文字(包含空白)
  • 用for逐字檢查每個字元
  • 用count%2==0來看是偶數還是奇數,如果是偶數輸出``,奇數輸出''
  • 如果不是引號,就直接輸出原字元

上一篇
cpe練習day8
下一篇
cpe練習day10
系列文
cpe30天練習19
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言